import 'package:date_format/date_format.dart';
import 'package:fate_blind_box/network/http_request.dart';
import 'package:fate_blind_box/ui/account/sex_info_model.dart';
import 'package:get/get.dart';

import '../../utils/loading.dart';
import '../../utils/page.dart';
import '../guide/download_new.dart';

class ProfileCompleteV4Controller extends GetxController {
  String sexViewId = 'sexViewId';
  String birthViewId = 'birthViewId';

  int realSex = 1;

  String dateStr = '点击设置';

  List sexList = [];

  void initSexData() {
    if(sexList.isNotEmpty){
      sexList.clear();
    }
    SexInfoModel manModel = SexInfoModel();
    manModel.sex = 1;
    manModel.nameStr = '男';
    manModel.isChose = true;
    sexList.add(manModel);

    SexInfoModel womanModel = SexInfoModel();
    womanModel.sex = 2;
    womanModel.nameStr = '女';
    womanModel.isChose = false;
    sexList.add(womanModel);
  }

  saveInformation() async{
    if(dateStr.contains('设置')){
      toast('请选择出生年月');
      return;
    }
    SexInfoModel choseModel=sexList.singleWhere((element) => (element.isChose==true));
     Map<String,dynamic>dataMap ={'realSex': choseModel.sex, 'birthYear': dateStr};
      final res = await HttpRequest.request('member/perfect/addInfoSex',
          params: dataMap);
      if (res['code'] == 0) {
        Navigate.toPage(const DownloadAppUiNew());
      } else {
        toast(res['msg']);
      }

  }
}
